package com.laboratory.eventlistenerlearning.service;

import com.laboratory.eventlistenerlearning.event.RoleEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RoleService {

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @Transactional
    public void createRole(String roleName) {
        System.out.println("创建角色：" + roleName);
        /**
         * 角色事件发布器
         */
        applicationEventPublisher.publishEvent(new RoleEvent("create role success"));
    }

}
